using System;
using System.Xml;
using System.Collections;
using System.Collections.Specialized;
using System.Xml.Serialization;

namespace ABC.XPath.Test.Models
{
	/// <summary>
	/// A request for products.
	/// </summary>
	[XmlRoot("Order", Namespace="http://emsinet.com/schemas/Order/Data")]
	public class Order
	{	
		private int _id;
		private DateTime _submittedDate;
		private string _clientOrderId;
		private IDictionary _requirements;
		private IDictionary _transactions;

		public Order()
		{}

		public Order(bool init)
		{
			ClientOrderId = "1234";
			SubmittedDate = new DateTime(2004, 1, 19, 3, 50, 0, 0);
			new Requirement
						{
							ClientUniqueId = "2468",
							ProcessingUniqueId = "923232",
							Type = new RequirementType(11, "APS"),
							RequestedDate = new DateTime(2005, 1, 29, 0, 56, 0, 0),
							State = new RequirementState
										{
											StateCode = new RequirementStateCode(75, "Accepted"),
											SubStateCode = new RequirementSubStateCode(3, "Reviewing")
										},
							CompletedDate = new DateTime(2005, 1, 29, 0, 56, 0, 0).AddDays(3),
							Order = this
						};
			new Requirement
						{
							ClientUniqueId = "124692",
							RequestedDate = new DateTime(2004, 1, 1, 19, 20, 0, 0),
							ProcessingUniqueId = "18342",
							Type = new RequirementType(4, "MVR"),
							State = new RequirementState { StateCode = new RequirementStateCode(3, "Completed") },
							Order = this
						};
			var tx = new OrderTransaction
						{
							Type = new OrderTransactionType(1, "Create"),
							Timestamp = new DateTime(2004, 1, 1, 19, 46, 13),
							ConfirmationNumber = "123456",
							Order = this
						};
			var clientRequest = new XmlDocument();
			clientRequest.LoadXml(@"<AnyClientRequest foo='bar' xmlns='kaitlyn'>Brenda</AnyClientRequest>");
			tx.ClientRequest = clientRequest.DocumentElement;
		}

		/// <summary>
		/// Gets/sets the order id.
		/// </summary>
		[XmlElement("OrderId",Namespace="http://emsinet.com/schemas/Order/Data")]
		public int Id
		{
			get { return _id; }
			set { _id = value; }
		}

		/// <summary>
		/// Gets/set the client supplied order id.
		/// </summary>
		[XmlElement("ClientOrderId",Namespace="http://emsinet.com/schemas/Order/Data")] 
		public string ClientOrderId 
		{
			get { return _clientOrderId; }
			set { _clientOrderId = value; }
		}

		/// <summary>
		/// Gets/set the date the order was submitted.
		/// </summary>
		[XmlElement("SubmittedDate",Namespace="http://emsinet.com/schemas/Order/Data")]
		public DateTime SubmittedDate
		{
			get { return _submittedDate; } 
			set { _submittedDate = value; }
		}

		/// <summary>
		/// Gets/sets the requirements of this order.
		/// </summary>
		[XmlAnyElement("Requirement",Namespace="http://emsinet.com/schemas/Order/Data")]
		public IDictionary Requirements
		{
			get
			{
				if (_requirements == null)
					_requirements = new ListDictionary();
				return _requirements;
			}
			set { _requirements = value; }
		}

		/// <summary>
		/// Gets/sets the transactions applied to this order.
		/// </summary>
		[XmlAnyElement("Transaction",Namespace="http://emsinet.com/schemas/Order/Data")]
		public IDictionary Transactions
		{
			get
			{
				if (_transactions == null)
					_transactions = new ListDictionary();
				return _transactions;
			}
			set { _transactions = value; }
		}
	}

	public class OrderTransactionType : TypeCode
	{
		/// <summary>
		/// Constructs an empty OrderTransactionType.
		/// </summary>
		public OrderTransactionType()
		{
			// empty
		}

		/// <summary>
		/// Constructs an initial OrderTransactionType.
		/// </summary>
		/// <param name="description">The OrderTransactionType description.</param>
		/// <param name="id">The OrderTransactionType id.</param>
		public OrderTransactionType(short id, string description)
			: base(id, description)
		{
			// empty
		}
	}
}
